﻿var isLogin = {
		data: function() {
			return {
				loginInfo: '', //用户信息
				loginState: false, //判断是否已登录
				showLogin: false, //控制登录显隐
				//          dialogState:true,
			}
		},
		methods: {
			//      isLogin: function () {
			//          var _this = this;
			//          $.ajax({
			//              //url: 'http://admin.gdxqjs.com/Admin/api/Auth/GetUserInfo',
			//              url: 'http://192.168.1.90:8011/WebAdmin/api/Auth/GetUserInfo',
			//              xhrFields: {
			//                  withCredentials: true
			//              },
			//              crossDomain: true,
			//              success: function (res) {
			//                  if (res.ErrorCode == 1) {
			//                      _this.loginState = true;
			//                      _this.loginInfo = res.data;
			//                  } else {
			//                      _this.loginState = false;
			//                  }
			//              },
			//              error: function (res) {
			//                  //debugger;
			//              },
			//              complete: function (res) {
			//                  //debugger;
			//              }
			//          });
			//      },
			//登录按钮
			loginBtn: function(param) {
				var _this = this;
				var method = 'Pub/CheckLogin';
				var param = {
					username: $.trim(param.username),
					verifycode: $.trim(param.verificationCode),
					password: $.trim(param.psw),
					rebackUrl: '',
				};
				xq.postUrl(method, param, function(res) {
					if(res.ErrorCode == 1) {
						res.data.LogTime = xq.getYMDHM(res.data.LogTime, 'yy/mm/dd');
						_this.loginState = true;
						_this.loginInfo = res.data;
						_this.showLogin = false;
						var overTime = new Date().getTime() + 86400000;
						xq.token = md5.md5(res.data.Token);
//						localStorage.setItem('user', JSON.stringify(res.data));
						//setCookie('JMEF_LoginUserKey_2017_V2.1.1', JSON.stringify(res.data), overTime);
						//setCookie('JMEF_LoginUserKey_2017_V2.1.1', encodeURI(JSON.stringify(res.data)), overTime);//需要编码
						_this.setCookie('JMEF_LoginUserKey_2017_V2.1.1', JSON.stringify(res.data), overTime); //需要编码
						//setCookie('JMEF_LoginUserKey_2017_V2.1.1', encodeURI(JSON.stringify(res.data)), overTime);//需要编码
					}
				});
			},
			//获取cookie
			getInfo: function() {
				//          var overTime = localStorage.getItem('overTime');
				//          var currentTime = new Date().getTime();
				//          if (currentTime < overTime) {
				//              this.loginState = true;
				//              this.loginInfo = JSON.parse(localStorage.getItem('user'));
				//          } else {
				//              this.loginState = false;
				//              this.loginInfo = '';
				//              xq.token = '';
				//          }
				var Cookie = xq.getCookie('JMEF_LoginUserKey_2017_V2.1.1');
				if(Cookie) {
					this.loginState = true;
					this.loginInfo = JSON.parse(Cookie);
				} else {
					this.loginState = false;
					this.loginInfo = '';
					xq.token = '';
				}
			},
			//判断是否已经登录的跳转
			toBackground: function() {
				if(!this.loginState) {
					this.showLogin = true;
				} else {
					window.open(xq.backgroundUrl + '?token=' + xq.token, '_black');
				}
			},
			//点击模态框隐藏登录框
			hideModal: function(isMoal) {
				if(isMoal) {
					this.showLogin = false;
				}
			},
			setCookie: function(c_name, value, expiredays) {
				var exdate = new Date();
				exdate.setDate(exdate.getDate() + expiredays);
				//document.cookie = c_name + "=" + escape(value);//+ ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/" + ";domain=";
				document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/" + ";domain=;";
			},
		},
		mounted: function() {
			this.getInfo();			
		}
}